stage.set_background("underwater")
sprite = codesters.Sprite("fish")
sprite.go_to(-100, -220)
stage.disable_floor()
stage.set_gravity(4)
sprite.set_gravity_off()
def right_key():
sprite.move_right(20)
# add other actions...
stage.event_key("right", right_key)
def left_key():
sprite.move_left(20)
# add other actions...
stage.event_key("left", left_key)
score = 0
#my_display = codesters.Display(my_var, x, y)
score_board = codesters.Display(score, -200, 200)
def interval():
rand_x = random.randint(-250, 250)
# add any other actions...
stage.event_interval(interval, 2)
t = codesters.Teacher()
circs = t.get_parameters_for_function('Circle')
circs_name = t.find_function('Circle')
try:
tval1 = circs[0][0]
tval2 = circs[0][1]
tval3 = circs[0][2]
tval4 = circs[0][3].replace('"', '')
except:
tval1 = "DNE"
tval2 = "DNE"
tval3 = "DNE"
tval4 = "DNE"
try:
tval5 = circs_name[0][1].split('=', 1)[0].replace(' ', '')
except:
tval5 = "DNE"
try:
tval6 = t.get_indent_at_line(circs_name[0][0])
except:
tval6 = "DNE"
t1 = TestObjective()
t1.add_success(tval5 == "food" and tval6 == 4, "Great job!")
t1.add_failure(tval5 == "DNE", "Did you add a Circle command inside your event?")
t1.add_failure(tval5 == 'sprite', "Did you change the circle's variable name to food?")
t1.add_failure(tval6 < 4, "Make sure you indent your Circle command inside your interval event.")
t1.add_failure(tval6 > 4, "Make sure you indent your Circle command only 4 spaces inside your interval event.")
t2 = TestObjective()
t2.add_success(tval1 == 'rand_x' and tval2 == '260' and tval3 == '10' and tval4 == 'sienna', "Great job!")
t2.add_failure(tval2 == '0' or tval3 == '0', "Did you change the circle's xy-coordinates?")
t2.add_failure(tval1 == "260" and tval2 == 'rand_x', "Oops! Did you switch your xy-coordinates?")
t2.add_failure('"' in tval1 or "'" in tval1, "Oops! Did you place rand_x in quotes?")
t2.add_failure(tval1 != "'rand_x'" and tval2 != '260', "Did you change your xy-coordinates correctly?")
t2.add_failure(tval3 != '10', "Did you change the circle's diameter to 10?")
t2.add_failure(tval4 == "blue", "Did you change the circle's color?")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)